package school.dao;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import school.domain.Student;
import school.util.DatabaseManager;

public class StudentDAO {

	private static StudentDAO instance;
	private SqlSessionFactory factory;
	private StudentDAO() {
		DatabaseManager manager = DatabaseManager.getInstance();
		factory = manager.getSqlSessionFactory();
	}
	
	public static StudentDAO getInstance() {
		if(instance==null) {
			instance = new StudentDAO();
		}
		return instance;
	}
	
	public Student selectStudentById(int studentId) {
		SqlSession session = factory.openSession();
		try{
			return session.selectOne("student.selectStudentById", studentId);
		}finally {
			session.close();
		}
	}
	
}
